home *** CD-ROM | disk | FTP | other *** search
/ Crosscountry USA Photo Safari / Crosscountry USA Photo Safari.iso / Data / cc_base / pak00_16bit_f.pk3 / common / init_scenario.c4 < prev    next >
Text File  |  2002-12-19  |  6KB  |  163 lines

  1.  
  2. {
  3.   @INIT_SCENARIO
  4.   {
  5.  
  6.     resid Player1;
  7.     resid Player2;
  8.     resid Player1Scenario;
  9.     resid Player2Scenario;
  10.     resid csv_data_id;
  11.     resid city_data_id;
  12.     resid state_data_id;
  13.     resid commodity_data_id;
  14.     resid CurCommodity;
  15.     int time_now;
  16.     int num_city;
  17.     int num_commodity;
  18.     int scenario_num_commodity;
  19.     int i;
  20.     int j;
  21.     int city_start;
  22.     int city_end;
  23.     str city_start_name;
  24.     str city_end_name;
  25.     int bonus_picked;
  26.     str bonus_commodity;
  27.     str tmp; 
  28.     str tmp2;
  29.     str start_state_name;
  30.     str end_state_name;
  31.     str startCityCommodity1;
  32.     str startCityCommodity2;
  33.     str startCityCommodity3;
  34.     str endCityCommodity1;
  35.     str endCityCommodity2;
  36.     str endCityCommodity3;    
  37.  
  38.     
  39.     Player1 = ResByName("Player1");
  40.     Player2 = ResByName("Player2");
  41.     Player1Scenario = ResByName("Player1Scenario");
  42.     Player2Scenario = ResByName("Player2Scenario");
  43.  
  44.     /* 
  45.      open up the cities csv file and pick the following:
  46.       - a random start city
  47.       - a random end city
  48.     */
  49.  
  50.     csv_data_id = ResByName("CSVData");
  51.     city_data_id = ResPropGetResID(csv_data_id, "city_id");
  52.     state_data_id = ResPropGetResID(csv_data_id, "state_id");
  53.     commodity_data_id = ResPropGetResID(csv_data_id, "commodity_id");
  54.  
  55.     num_city = CSVGetRowCount(city_data_id);
  56.     
  57.     num_commodity = CSVGetRowCount(commodity_data_id);
  58.     
  59.     RandomDeckShuffle(num_city);
  60.     city_start = RandomDeckGetCard();   
  61.     city_end = RandomDeckGetCard();
  62.  
  63.     while (CSVGetInt(city_data_id,"can_start_in",city_start) != 1) {
  64.       city_start = RandomDeckGetCard();
  65.     } 
  66.     while (CSVGetInt(city_data_id,"can_start_in",city_end) != 1) {
  67.       city_end = RandomDeckGetCard();     
  68.     } 
  69.   
  70.     tmp = CSVGetStr(city_data_id, "name", city_start);
  71.     ResPropSetStr(Player1Scenario,"scenario_start_city", tmp);
  72.     ResPropSetStr(Player2Scenario,"scenario_start_city", tmp);
  73.  
  74.     tmp = CSVGetStr(city_data_id, "name", city_end);
  75.     ResPropSetStr(Player1Scenario,"scenario_end_city", tmp);    
  76.     ResPropSetStr(Player2Scenario,"scenario_end_city", tmp);    
  77.     
  78.     /* get the start state */
  79.     start_state_name = CSVGetStr(state_data_id,"name", 
  80.                          CSVSearch(state_data_id,"abbreviation", 
  81.                            CSVGetStr(city_data_id,"state", city_start)
  82.                          )
  83.                        );
  84.     
  85.     /* get the end state */
  86.     end_state_name = CSVGetStr(state_data_id,"name",
  87.                          CSVSearch(state_data_id,"abbreviation", 
  88.                            CSVGetStr(city_data_id,"state", city_end)
  89.                          )
  90.                        );                       
  91.     
  92.     ResPropSetStr(Player1Scenario,"scenario_start_state", start_state_name);
  93.     ResPropSetStr(Player2Scenario,"scenario_start_state", start_state_name);
  94.  
  95.     ResPropSetStr(Player1Scenario,"scenario_end_state", end_state_name);
  96.     ResPropSetStr(Player2Scenario,"scenario_end_state", end_state_name);
  97.  
  98.     startCityCommodity1 = CSVGetStr(city_data_id, "com1", city_start);
  99.     startCityCommodity2 = CSVGetStr(city_data_id, "com2", city_start);
  100.     startCityCommodity3 = CSVGetStr(city_data_id, "com3", city_start);
  101.     endCityCommodity1 = CSVGetStr(city_data_id, "com1", city_end);
  102.     endCityCommodity2 = CSVGetStr(city_data_id, "com2", city_end);
  103.     endCityCommodity3 = CSVGetStr(city_data_id, "com3", city_end);
  104.        
  105.     RandomDeckShuffle(num_commodity);
  106.     i=0;
  107.     bonus_picked = 0;
  108.     scenario_num_commodity = ResPropGetInt(Player1Scenario,"scenario_commodity_number_of");
  109.  
  110.     ResPropSetInt(Player2Scenario, "scenario_commodity_number_of", scenario_num_commodity);
  111.  
  112.     ResPropSetInt(Player1, "commodity_number_of", scenario_num_commodity);
  113.     ResPropSetInt(Player2, "commodity_number_of", scenario_num_commodity);
  114.  
  115.     while (i < scenario_num_commodity) {
  116.       j = RandomDeckGetCard();
  117.       tmp = CSVGetStr(commodity_data_id, "name", j);
  118.       while (
  119.           StrExact(tmp, startCityCommodity1) ||
  120.           StrExact(tmp, startCityCommodity2) ||
  121.           StrExact(tmp, startCityCommodity3) ||
  122.           StrExact(tmp, endCityCommodity1) ||
  123.           StrExact(tmp, endCityCommodity2) ||
  124.           StrExact(tmp, endCityCommodity3)
  125.         ) {
  126.         j = RandomDeckGetCard();        
  127.         tmp = CSVGetStr(commodity_data_id, "name", j);
  128.       }
  129.       
  130.       /* get bonus commodity for player1 and player2 */
  131.       if (bonus_picked == 0) {
  132.         ResPropSetStr(Player1Scenario,"scenario_commodity_bonus", tmp);
  133.         ResPropSetStr(Player2Scenario,"scenario_commodity_bonus", tmp);
  134.     
  135.         CurCommodity = ResByName("player1_commodity_bonus");
  136.         ResPropSetStr(CurCommodity,"commodity_name",tmp);
  137.         ResPropSetInt(CurCommodity,"commodity_state",0);
  138.         
  139.         CurCommodity = ResByName("player2_commodity_bonus");
  140.         ResPropSetStr(CurCommodity,"commodity_name",tmp);
  141.         ResPropSetInt(CurCommodity,"commodity_state",0);
  142.         
  143.         bonus_picked = 1;       
  144.       } else {   /* get regular commodity for player1 and player2 */     
  145.         tmp2 = StrFormatStr("scenario_commodity_name_%d", i+1);
  146.         ResPropSetStr(Player1Scenario, tmp2, tmp);
  147.         ResPropSetStr(Player2Scenario, tmp2, tmp);
  148.   
  149.         CurCommodity = ResByName(StrFormatStr("player1_commodity_%d",i+1));
  150.         ResPropSetStr(CurCommodity,"commodity_name",tmp);
  151.         ResPropSetInt(CurCommodity,"commodity_state",0);
  152.         
  153.         CurCommodity = ResByName(StrFormatStr("player2_commodity_%d",i+1));
  154.         ResPropSetStr(CurCommodity,"commodity_name",tmp);
  155.         ResPropSetInt(CurCommodity,"commodity_state",0);
  156.         
  157.         i+=1;
  158.       }
  159.     }
  160.   }
  161. }      
  162.       
  163.